#include<iostream>
#include<vector>
using namespace std;
#include<algorithm>
#include<string>



class Solution {
public:
    vector<string> readBinaryWatch(int turnedOn) {
        vector<string> ret;
        if(turnedOn >= 9) return ret;

        vector<vector<int>> Hour = {{0}, {1,2,4,8}, {3,5,6,9,10}, {7,11}};
        vector<vector<int>> Minute;
        Minute.resize(6);
        int Minute_List[] = {32,16,8,4,2,1};
        for(int i = 0; i <= 59; ++i){
            int cnt = 0, j = 0, i_copy = i;
            while(j < 6 && i_copy > 0){
                if(i_copy >= Minute_List[j]){
                    i_copy -= Minute_List[j];
                    ++cnt;
                } 
                ++j;
            }
            Minute[cnt].push_back(i);
        }

        //经过分析，小时最多三个灯，分钟最多是5个灯
        int Minute_Light = (turnedOn > 5) ? 5 : turnedOn;
        int Hour_Light = turnedOn - Minute_Light;
        while(Hour_Light <= 3 && Minute_Light >= 0){
            //往ret内添加时间
            int houri = 0;
            while(houri < Hour[Hour_Light].size()){
                int minutei = 0;
                while(minutei < Minute[Minute_Light].size()){
                    string H = to_string(Hour[Hour_Light][houri]);
                    string M = to_string(Minute[Minute_Light][minutei]);
                    if(Minute[Minute_Light][minutei] < 10){
                        M += "0";
                        reverse(M.begin(), M.end());
                    }

                    ret.push_back((H + ":" + M));
                    ++minutei;
                }
                ++houri;
            }
            ++Hour_Light;
            --Minute_Light;
        }
        return ret;
    }
};
